﻿using System;
using System.ServiceModel;
using System.Transactions;
using WCFIServices;

namespace WCFServerService
{
	public class ServerPushMessageBO
	{
		public void SendPushMessage(string message, string pushMessageBoxAddress)
		{
			NetMsmqBinding msmqCallbackBinding = new NetMsmqBinding();
			msmqCallbackBinding.Security.Mode = NetMsmqSecurityMode.None;

			MessageBoxClient messageBoxClient = new MessageBoxClient(msmqCallbackBinding, new EndpointAddress(pushMessageBoxAddress));

			try
			{
				using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
				{
					MessageData messageData = new MessageData();

					messageData.Message = message;
					messageData.PushMessageUTCTimeStamp = DateTime.UtcNow.Ticks;

					messageBoxClient.MessageBox(messageData);

					scope.Complete();
				}
			}
			catch
			{
			}

			messageBoxClient.Close();
		}

        public void SendPushMessage(Employee employee, string pushMessageBoxAddress)
        {
            var msmqCallbackBinding = new NetMsmqBinding {Security = {Mode = NetMsmqSecurityMode.None}};

            var messageBoxClient = new MessageBoxClient(msmqCallbackBinding, new EndpointAddress(pushMessageBoxAddress));

            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //MessageData messageData = new MessageData();

                    //messageData.Message = message;
                    //messageData.PushMessageUTCTimeStamp = DateTime.UtcNow.Ticks;

                    messageBoxClient.MessageBoxWithEmployee(employee);

                    scope.Complete();
                }
            }
            catch
            {
            }

            messageBoxClient.Close();
        }

	}
}
